﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;


namespace GUI
{
    public partial class frmQuanTri : Form
    {
        public frmQuanTri()
        {
            InitializeComponent();
        }
        public static UserDTO p = new UserDTO();
        public static UserBUS bus = new UserBUS();
        private void frmQuanTri_Load(object sender, EventArgs e)
        {
            List<UserDTO> dscn = bus.GetAll();
            dgvuser.DataSource = dscn;
        }


        private void dgvuser_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = 0;
            row = e.RowIndex;
            if (row < 0)
            {
                return;
            }
            txtMaUser.Text = dgvuser.CurrentRow.Cells[0].Value.ToString();
            txtMaNV.Text = dgvuser.CurrentRow.Cells[1].Value.ToString();
            txtusername.Text = dgvuser.CurrentRow.Cells[2].Value.ToString();
            txtpass.Text = dgvuser.CurrentRow.Cells[3].Value.ToString();
        }
        private void btthem_Click(object sender, EventArgs e)
        {
            p.Mauser = txtMaUser.Text.Trim();
            p.Manv = txtMaNV.Text.Trim();
            p.Username = txtusername.Text.Trim();
            p.Pass = txtpass.Text.Trim();
            bool kq = bus.Insert(p);
            if (kq == true)
            {
                MessageBox.Show("Thêm thành công");
                frmQuanTri_Load(sender, e);
            }
            else
                MessageBox.Show("Thêm không thành công");
        }

        private void btSua_Click(object sender, EventArgs e)
        {
            p.Mauser = txtMaUser.Text.Trim();
            p.Manv = txtMaNV.Text.Trim();
            p.Username = txtusername.Text.Trim();
            p.Pass = txtpass.Text.Trim();
            bool kq = bus.Update(p);
            if (kq == true)
            {
                MessageBox.Show("Sửa thành công");
                frmQuanTri_Load(sender, e);
            }
            else
                MessageBox.Show("Sửa không thành công");
        }

        private void btxoa_Click(object sender, EventArgs e)
        {
            p.Mauser = txtMaUser.Text.Trim();
            bool kq = bus.Delete(p);
            if (kq == true)
            {
                MessageBox.Show("Xóa thành công");
                frmQuanTri_Load(sender, e);
            }
            else
                MessageBox.Show("Xóa không thành công");
        }


    }
}
